﻿using KZ.Express.ENT;
using KZ.Express.Resource;
using KZ.Express.Task;
using KZ.Utilities;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KZ.Express.Presenter
{
    public interface IRoleDetailView : IViewBase
    {
        DataTable Objects { get; }
    }

    public class RoleDetailPresenter : PresenterBase
    {
        new RoleTask _task;
        new IRoleDetailView _view;

        public RoleDetailPresenter(IRoleDetailView view)
            : base(view, new RoleENT())
        {
            _view = view;
            _task = new RoleTask();
        }

        public override void Save()
        {
            try
            {
                RoleENT role = _view.Entity as RoleENT;
                if (_view.Action == ActionName.Insert)
                {
                    if (_task.Insert(role, _view.Objects) > 0)
                    {
                        _view.Entity = null;
                        _view.SetMessage(Message.BLM_SUC_INSERT.ToString(), true);
                    }
                }
                else if (_view.Action == ActionName.Update)
                {
                    if (_task.Update(role, _view.Objects) > 0)
                        _view.SetMessage(Message.BLM_SUC_UPDATE.ToString(), true);
                }
            }
            catch (DataAccessException ex)
            {
                throw new BusinessLogicException(ex.Message);
            }
        }
    }
}
